package com.example.administrator.yuejian35.Club.activity;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;

import com.example.administrator.yuejian35.Club.adapter.ClubListAdapter;
import com.example.administrator.yuejian35.Club.bean.Club;
import com.example.administrator.yuejian35.Club.model.ClubModel;
import com.example.administrator.yuejian35.R;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class SearchClubActivity extends AppCompatActivity {
    private RecyclerView clubsearch_rv;
    private List<Club> list;
    private ImageView master_view;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_search_club);

        clubsearch_rv= (RecyclerView) findViewById(R.id.clubsearch_rv);
        master_view= (ImageView) findViewById(R.id.video_pic);

        master_view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
        final String get = getIntent().getStringExtra("get");

         ClubModel clubmodel1 = new ClubModel();
               Call call1 = clubmodel1.searchclub(get);
                call1.enqueue(new Callback<List<Club>>() {
                    @Override
                    public void onResponse(Call<List<Club>> call, Response<List<Club>> response) {
                        if(SearchClubActivity.this!=null) {
                            list = response.body();
                   /* Toast.makeText(getActivity(),"111",Toast.LENGTH_LONG).show();
                    Toast.makeText(getActivity(),list.get(1).getClubname().toString()+"11111111",Toast.LENGTH_LONG).show();*/
                            ClubListAdapter adapter = new ClubListAdapter(SearchClubActivity.this, list);

                            LinearLayoutManager layoutManager = new LinearLayoutManager(SearchClubActivity.this);
                            layoutManager.setOrientation(LinearLayoutManager.VERTICAL);//Horizontal

                            //Grid
                            clubsearch_rv.setLayoutManager(layoutManager);
                            clubsearch_rv.setAdapter(adapter);
                            clubsearch_rv.setItemAnimator(new DefaultItemAnimator());
                        }
                    }

                    @Override
                    public void onFailure(Call<List<Club>> call, Throwable t) {

                    }
                });
    }
}
